/**
 * Copyright 2025 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

#textfield {
    --spectrum-search-inline-size: var(--spectrum-field-width);
    --spectrum-search-block-size: var(--spectrum-component-height-100);
    --spectrum-search-button-inline-size: var(--spectrum-search-block-size);
    --spectrum-search-min-inline-size: calc(var(--spectrum-search-field-minimum-width-multiplier) * var(--spectrum-search-block-size));
    --spectrum-search-icon-size: var(--spectrum-workflow-icon-size-100);
    --spectrum-search-text-to-icon: var(--spectrum-text-to-visual-100);
    --spectrum-search-to-help-text: var(--spectrum-help-text-to-component);
    --spectrum-search-top-to-text: var(--spectrum-component-top-to-text-100);
    --spectrum-search-bottom-to-text: var(--spectrum-component-bottom-to-text-100);
    --spectrum-search-focus-indicator-thickness: var(--spectrum-focus-indicator-thickness);
    --spectrum-search-focus-indicator-gap: var(--spectrum-focus-indicator-gap);
    --spectrum-search-focus-indicator-color: var(--spectrum-focus-indicator-color);
    --spectrum-search-font-family: var(--spectrum-sans-font-family-stack);
    --spectrum-search-font-weight: var(--spectrum-regular-font-weight);
    --spectrum-search-font-style: var(--spectrum-default-font-style);
    --spectrum-search-line-height: var(--spectrum-line-height-100);
    --spectrum-search-color-default: var(--spectrum-neutral-content-color-default);
    --spectrum-search-color-hover: var(--spectrum-neutral-content-color-hover);
    --spectrum-search-color-focus: var(--spectrum-neutral-content-color-focus);
    --spectrum-search-color-focus-hover: var(--spectrum-neutral-content-color-focus-hover);
    --spectrum-search-color-key-focus: var(--spectrum-neutral-content-color-key-focus);
    --spectrum-search-border-width: var(--spectrum-border-width-100);
    --spectrum-search-color-disabled: var(--spectrum-disabled-content-color);
    --mod-textfield-font-family: var(--mod-search-font-family, var(--spectrum-search-font-family));
    --mod-textfield-font-weight: var(--mod-search-font-weight, var(--spectrum-search-font-weight));
    --mod-textfield-corner-radius: var(--mod-search-border-radius, var(--spectrum-search-border-radius));
    --mod-textfield-border-width: var(--mod-search-border-width, var(--spectrum-search-border-width));
    --mod-textfield-focus-indicator-gap: var(--mod-search-focus-indicator-gap, var(--spectrum-search-focus-indicator-gap));
    --mod-textfield-focus-indicator-width: var(--mod-search-focus-indicator-thickness, var(--spectrum-search-focus-indicator-thickness));
    --mod-textfield-focus-indicator-color: var(--mod-search-focus-indicator-color, var(--spectrum-search-focus-indicator-color));
    --mod-textfield-text-color-default: var(--mod-search-color-default, var(--spectrum-search-color-default));
    --mod-textfield-text-color-hover: var(--mod-search-color-hover, var(--spectrum-search-color-hover));
    --mod-textfield-text-color-focus: var(--mod-search-color-focus, var(--spectrum-search-color-focus));
    --mod-textfield-text-color-focus-hover: var(--mod-search-color-focus-hover, var(--spectrum-search-color-focus-hover));
    --mod-textfield-text-color-keyboard-focus: var(--mod-search-color-key-focus, var(--spectrum-search-color-key-focus));
    --mod-textfield-text-color-disabled: var(--mod-search-color-disabled, var(--spectrum-search-color-disabled));
    --mod-textfield-border-color: var(--mod-search-border-color-default, var(--spectrum-search-border-color-default));
    --mod-textfield-border-color-hover: var(--mod-search-border-color-hover, var(--spectrum-search-border-color-hover));
    --mod-textfield-border-color-focus: var(--mod-search-border-color-focus, var(--spectrum-search-border-color-focus));
    --mod-textfield-border-color-focus-hover: var(--mod-search-border-color-focus-hover, var(--spectrum-search-border-color-focus-hover));
    --mod-textfield-border-color-keyboard-focus: var(--mod-search-border-color-key-focus, var(--spectrum-search-border-color-key-focus));
    --mod-textfield-border-color-disabled: var(--mod-search-border-color-disabled, var(--spectrum-search-border-color-disabled));
    --mod-textfield-background-color: var(--mod-search-background-color, var(--spectrum-search-background-color));
    --mod-textfield-background-color-disabled: var(--mod-search-background-color-disabled, var(--spectrum-search-background-color-disabled));
    inline-size: var(--mod-search-inline-size, var(--spectrum-search-inline-size));
    min-inline-size: var(--mod-search-min-inline-size, var(--spectrum-search-min-inline-size));
    display: inline-block;
    position: relative;
}

#textfield .spectrum-HelpText {
    margin-block-start: var(--mod-search-to-help-text, var(--spectrum-search-to-help-text));
}

:host([size="s"]) #textfield {
    --spectrum-search-block-size: var(--spectrum-component-height-75);
    --spectrum-search-icon-size: var(--spectrum-workflow-icon-size-75);
    --spectrum-search-text-to-icon: var(--spectrum-text-to-visual-75);
}

:host([size="l"]) #textfield {
    --spectrum-search-block-size: var(--spectrum-component-height-200);
    --spectrum-search-icon-size: var(--spectrum-workflow-icon-size-200);
    --spectrum-search-text-to-icon: var(--spectrum-text-to-visual-200);
}

:host([size="xl"]) #textfield {
    --spectrum-search-block-size: var(--spectrum-component-height-300);
    --spectrum-search-icon-size: var(--spectrum-workflow-icon-size-300);
    --spectrum-search-text-to-icon: var(--spectrum-text-to-visual-300);
}

@media (forced-colors: active) {
    #textfield #textfield,
    #textfield #textfield .input {
        --highcontrast-search-color-default: CanvasText;
        --highcontrast-search-color-hover: CanvasText;
        --highcontrast-search-color-focus: CanvasText;
        --highcontrast-search-color-disabled: GrayText;
    }

    #textfield #button .spectrum-ClearButton-fill {
        forced-color-adjust: none;
        background-color: initial;
    }
}

#button {
    position: absolute;
    inset-block-start: 0;
    inset-inline-end: 0;
}

#button,
#button .spectrum-ClearButton-fill {
    border-radius: var(--mod-search-border-radius, var(--spectrum-search-border-radius));
}

#textfield.is-disabled #button {
    display: none;
}

#textfield {
    inline-size: 100%;
}

.icon-search {
    --spectrum-search-color: var(--highcontrast-search-color-default, var(--mod-search-color-default, var(--spectrum-search-color-default)));
    color: var(--spectrum-search-color);
    margin-block: auto;
    display: block;
    position: absolute;
    inset-block: 0;
}

#textfield.is-focused .icon-search {
    --spectrum-search-color: var(--highcontrast-search-color-focus, var(--mod-search-color-focus, var(--spectrum-search-color-focus)));
}

#textfield.is-keyboardFocused .icon-search {
    --spectrum-search-color: var(--highcontrast-search-color-focus, var(--mod-search-color-key-focus, var(--spectrum-search-color-key-focus)));
}

#textfield.is-disabled .icon-search {
    --spectrum-search-color: var(--highcontrast-search-color-disabled, var(--mod-search-color-disabled, var(--spectrum-search-color-disabled)));
}

@media (hover: hover) {
    #textfield:hover .icon-search {
        --spectrum-search-color: var(--highcontrast-search-color-hover, var(--mod-search-color-hover, var(--spectrum-search-color-hover)));
    }

    #textfield.is-focused:hover .icon-search {
        --spectrum-search-color: var(--highcontrast-search-color-focus, var(--mod-search-color-focus-hover, var(--spectrum-search-color-focus-hover)));
    }

    #textfield.is-disabled:hover .icon-search {
        --spectrum-search-color: var(--highcontrast-search-color-disabled, var(--mod-search-color-disabled, var(--spectrum-search-color-disabled)));
    }
}

.input {
    appearance: none;
    block-size: var(--mod-search-block-size, var(--spectrum-search-block-size));
    font-style: var(--mod-search-font-style, var(--spectrum-search-font-style));
    line-height: var(--mod-search-line-height, var(--spectrum-search-line-height));
    padding-block-start: calc(var(--mod-search-top-to-text, var(--spectrum-search-top-to-text)) - var(--mod-search-border-width, var(--spectrum-search-border-width)));
    padding-block-end: calc(var(--mod-search-bottom-to-text, var(--spectrum-search-bottom-to-text)) - var(--mod-search-border-width, var(--spectrum-search-border-width)));
}

.input::-webkit-search-cancel-button,
.input::-webkit-search-decoration {
    appearance: none;
}

:host(:not([quiet])) #textfield .icon-search {
    inset-inline-start: var(--mod-search-edge-to-visual, var(--spectrum-search-edge-to-visual));
}

:host(:not([quiet])) #textfield .input {
    padding-inline-start: calc(var(--mod-search-edge-to-visual, var(--spectrum-search-edge-to-visual)) - var(--mod-search-border-width, var(--spectrum-search-border-width)) + var(--mod-search-icon-size, var(--spectrum-search-icon-size)) + var(--mod-search-text-to-icon, var(--spectrum-search-text-to-icon)));
    padding-inline-end: var(--mod-search-button-inline-size, var(--spectrum-search-button-inline-size));
}

:host([quiet]) {
    --spectrum-search-background-color: transparent;
    --spectrum-search-background-color-disabled: transparent;
    --spectrum-search-border-color-disabled: var(--spectrum-disabled-border-color);
    --mod-search-border-radius: 0;
    --mod-search-edge-to-visual: var(--spectrum-field-edge-to-visual-quiet);
}

:host([quiet]) .input {
    border-radius: var(--mod-search-border-radius, var(--spectrum-search-border-radius));
    padding-block-start: var(--mod-search-top-to-text, var(--spectrum-search-top-to-text));
    padding-inline-start: calc(var(--mod-search-edge-to-visual, var(--spectrum-search-edge-to-visual)) + var(--mod-search-icon-size, var(--spectrum-search-icon-size)) + var(--mod-search-text-to-icon, var(--spectrum-search-text-to-icon)));
    padding-inline-end: var(--mod-search-button-inline-size, var(--spectrum-search-button-inline-size));
}
